<!DOCTYPE HTML>
<html>
<head>
    <title>户籍迁移办理</title>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
    <script src="/webjars/miniui/boot.js" type="text/javascript"></script>
    <link href="/static/css/resource.css" rel="stylesheet" type="text/css"/>
    <link href="/static/css/default.css" rel="stylesheet" type="text/css"/>
    <script src="/static/js/common/common.js" type="text/javascript"></script>
</head>
<style>
    .hideBorder{
        border: solid 0px;
    }
</style>

<body onload="onLoad()">
<div class="mini-fit" style="margin-bottom: 40px">
    <div style="height:100%;width: 100%;overflow-x: auto;overflow-y: auto;">
        <form id="form1" method="post" style="margin-top: 10px;">
            <div id="editform" class="form" >
                <table class="form-table" >
                    <#if !priNum?? >
                        <tr>
                            <td width="150" align="right"><font color="#dc143c">*</font>姓&emsp;&emsp;名:</td>
                            <td style="width: 200px">
                                <div property="editor" id="queryName" class="mini-autocomplete" required="true" style="width:490px;" valueField="id" textField="name"
                                     url="/azbj/bjdxInfo/hjqr/addPrisonerMv/getPrisonerList" showColumns="false"  onvaluechanged="getQueryName()" popupEmptyText="未查询到值......">
                                    <div property="columns">
                                        <div field="name"  ></div>
                                        <div field="hjd" ></div>
                                        <div field="idnum" ></div>
                                    </div>
                                </div>
                            </td>
                        </tr>
                    </#if>
                    <#if priNum?? >
                        <tr>
                            <td width="150" align="right"><font color="#dc143c">*</font>姓&emsp;&emsp;名:</td>
                            <td style="width: 200px">
                                <div property="editor" id="queryName" class="mini-autocomplete" required="true" style="width:490px;" valueField="id" textField="name" enabled='false'
                                     url="/azbj/bjdxInfo/hjqr/addPrisonerMv/getPrisonerList" showColumns="false"  onvaluechanged="getQueryName()" popupEmptyText="未查询到值......">
                                    <div property="columns">
                                        <div field="name"  ></div>
                                        <div field="hjd" ></div>
                                        <div field="idnum" ></div>
                                    </div>
                                </div>
                            </td>
                        </tr>
                    </#if>
                </table>
            </div>
        </form>
        <form id="form2" method="post">
            <div id="editform" class="form">
                <#--罪犯编号-->
                <input id="priNumNew" name="priNumNew" class="mini-hidden"/>
                <table>
                    <tr>
                        <td width="150" align="right"><span style="color: #8B8B8B">姓&emsp;&emsp;名:</span></td>
                        <td>
                            <input id="name" name="name" class="mini-textbox" borderStyle="border:0;" style="width: 500px;" readonly />
                        </td>
                    </tr>
                    <tr>
                        <td width="150" align="right"><span style="color: #8B8B8B">性&emsp;&emsp;别:</span></td>
                        <td>
                            <input id="sex" name="sex" class="mini-textbox" borderStyle="border:0"style="width: 500px;color: #8B8B8B" readonly />
                        </td>
                    </tr>
                    <tr>
                        <td width="150" align="right"><span style="color: #8B8B8B">身份证号:</span></td>
                        <td>
                            <input id="idnum" name="idnum" class="mini-textbox" borderStyle="border:0" style="width: 500px;color: #8B8B8B" readonly />
                        </td>
                    </tr>
                    <tr>
                        <td width="150" align="right"><span style="color: #8B8B8B">出生日期:</span></td>
                        <td>
                            <input id="age" name="age" class="mini-textbox" borderStyle="border:0" style="width: 500px;color: #8B8B8B" readonly/>
                        </td>
                    </tr>
                    <tr>
                        <td width="150" align="right"><span style="color: #8B8B8B">户籍地址:</span></td>
                        <td>
                            <input id="hujidi" name="hujidi" class="mini-textbox" borderStyle="border:0" style="width: 500px;color: #8B8B8B" readonly/>
                        </td>
                    </tr>
                    <tr>
                        <td width="150" align="right"><span style="color: #8B8B8B">居住地址:</span></td>
                        <td>
                            <input id="juzhudi" name="juzhudi" class="mini-textbox" borderStyle="border:0" style="width: 500px;color: #8B8B8B" readonly />
                        </td>
                    </tr>
                </table>
            </div>
        </form>
        <form id="form3" method="post">
            <div id="editform" class="form" >
                <#--罪犯编号-->
                <input id="priNum" name="priNum" value="${priNum!''}" class="mini-hidden"/>
                <#--id-->
                <input id="id" name="id" value="${id!''}"  class="mini-hidden"/>
                <table class="form-table" align="center" style="width: 95%;margin-left: 0px;" cellspacing="5" >
                    <tr>
                        <td width="150" align="right"><font color="#dc143c">*</font>户籍迁入地址:</td>
                        <td colspan="3">
                            <input  id = "nativeinpro" name="nativeinpro"  class="mini-combobox" required="true" emptyText = "省份" style="width:24%;"
                                    textfield="codeName" valueField="codeId" url="/azbj/bjdxInfo/getDepart?codeType=2_1&codeId=-1" value="${nativeinpro!''}"
                                    onclick="onDeptChanged('nativeinpro')" onvaluechanged = "onValueChanged('nativeinpro')"/>

                            <input  id = "nativeincity" name="nativeincity"  class="mini-combobox" required="true"  emptyText = "市" style="width:24%;"
                                    textfield="codeName" valueField="codeId" onclick="onDeptChanged('nativeincity')" value="${nativeincity!''}"
                                    onvaluechanged = "onValueChanged('nativeincity')" url = "/azbj/bjdxInfo/getDepart?codeType=2_1&codeId=${nativeinpro!''}"  />

                            <input  id = "nativeincou" name="nativeincou"  class="mini-combobox" required="true"  emptyText = "县" style="width:24%;"
                                    textfield="codeName" valueField="codeId" onclick="onDeptChanged('nativeincou')" value="${nativeincou!''}"
                                    onvaluechanged = "onValueChanged('nativeincou')" url = "/azbj/bjdxInfo/getDepart?codeType=2_1&codeId=${nativeincity!''}" />

                            <input  id = "nativeinvill" name="nativeinvill"  class="mini-combobox" required="true"  emptyText = "街道" style="width:24%;"
                                    url = "/azbj/bjdxInfo/getStreet?parent_code=${nativeincou!''}"
                                    textfield="name" valueField="code"onclick="onDeptChanged('nativeinvill')"   value="${nativeinvillName!''}" />
                        </td>
                    </tr>
                    <tr>
                        <td width="150" align="right"></td>
                        <td style="width: 200px">
                            <input class="mini-textbox" style="width: 490px" emptyText = "详细地址" id="nativeinnum" name="nativeinnum"  value="${nativeinnum!''}" required="true" />
                        </td>
                    </tr>
                    <tr>
                        <td width="150" align="right"><font color="#dc143c">*</font>联&ensp;系&ensp;人:</td>
                        <td style="width: 200px">
                            <input id="qclxr"  name="qclxr" class="mini-textbox" style="width: 490px;"  value="${qclxr!''}"  required="true"/>
                        </td>
                    </tr>
                    <tr>
                        <td width="150" align="right">发起迁移人员手机号码:</td>
                        <td style="width: 200px">
                            <input id="qclxdh"  name="qclxdh" class="mini-textbox" style="width: 490px;" onvaluechanged="checkPhone(2)" emptyText="请输入手机号码" value="${qclxdh!''}"/>
                        </td>
                    </tr>
                    <tr>
                        <td width="150" align="right">发起迁移人员固话:</td>
                        <td>
                            <input id="fixedLine"  name="fixedLine" class="mini-textbox" style="width: 490px;" onvaluechanged="checkPhone(1)" emptyText="请输入固定电话" value="${fixedLine!''}"/>
                        </td>
                    </tr>
                    <tr>
                        <td width="150" align="right"><font color="#dc143c">*</font>备&emsp;&emsp;注:</td>
                        <td>
                            <input id="remark"  name="remark" class="mini-textarea" style="width: 490px;" emptyText="请输入内容(0-200):" maxlength="200"  value="${remark!''}" required="true" />
                        </td>
                    </tr>
                    <tr>
                        <td width="150" align="right"><font color="#dc143c">*</font>申请时间:</td>
                        <td style="width: 200px">
                            <input id="outapplytime"  name="outapplytime" allowInput="true" class="mini-datepicker" value="${outapplytime!''}"  style="width: 200px" required="true"
                                   nullValue="null" format="yyyy-MM-dd" showTime="true"
                                   showOkButton="true" enabled="false" showClearButton="false" />
                        </td>
                    </tr>
                </table>
            </div>
        </form>
        <form id="form4" method="post">
            <!-- 用户 编辑框START-->
            <div id="fileform" class="form">
                <table id="fjscTb" class="form-table"  >
                    <tr>
                        <td width="150" align="right">
                            附件上传:
                        </td>
                        <td >
                            <div  >
                                <input type="button" value="上传附件" onclick="onFileUpload()">
                                <span id="msg1"></span>
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <td width="150" align="center" style="line-height: 15px;" >

                        </td>
                        <td width="300px">
<#--                            <span  style="color: #8B8B8B" >支持扩展名:.rar .zip .doc .docx .xls .xlsx .pdf .jpg...</span>-->
                            <div><b>支持扩展名:</b>.rar .zip .doc .docx .xls .xlsx .pdf .jpg</div>
                        </td>
                    </tr>

                </table>
            </div>
        </form>
    </div>
</div>
<div style="position: absolute;bottom: 0;line-height:40px;width: 100%;border-top: 1px solid #dfdfdf;text-align: center">
    <a class="mini-button" iconCls="fa-save" plain="true" onclick="saveData()">保存</a>
    <a class="mini-button" iconCls="fa-undo" plain="true" onclick="close('cancel')">取消</a>
</div>

<script type="text/javascript">
    mini.parse();
    var form1 = new mini.Form("form1");
    var form2 = new mini.Form("form2");
    var form3 = new mini.Form("form3");
    var queryNameObj = mini.get("queryName");
    var priNumObj = mini.get("priNum");
    var idObj = mini.get("id");
    var nativeinpro = mini.get("nativeinpro");
    var nativeincity = mini.get("nativeincity");
    var nativeincou = mini.get("nativeincou");
    var nativeinvill = mini.get("nativeinvill");
    var nativenum = mini.get("nativenum");

    function onLoad(){
        // 得到id
        var id = idObj.getValue();
        var priNum = priNumObj.getValue();
        getQueryName(priNum);
        // 查询户籍迁移上传附件
        $.ajax({
            url: "/upload/downloadAppendixFile/getCountById?1=1&priNum="+priNum+"&taskId=13" + "&id=" + id,
            type: 'get',
            success: function (success){
                $("#msg1").text("上传成功" + success.data + "条!");
            }
        })
    }

    function checkPhone(e){
        var qclxdh = mini.get("qclxdh").getValue();
        var fixedLine = mini.get("fixedLine").getValue();
        if (e == '1') {
            if(!validateTel(fixedLine)) {
                mini.alert("固定电话有误，请重填");
            }
        }
        if (e == '2') {
            if(!validatePhone1(qclxdh)) {
                mini.alert("手机号码有误，请重填");
            }
        }
    }

    function saveData(){
        form1.validate();
        form3.validate();
        if (form1.isValid() == false) {
            return;
        }
        if (form3.isValid() == false) {
            return;
        }
        var data = form3.getData();
        var tel = data.fixedLine;
        var phone = data.qclxdh;
        var newPhone = checkTelAndPhone(tel,phone);
        var flag = newPhone['flag'];
        var kflag = newPhone['kflag'];
        if('-1'===kflag){
            mini.alert("请至少输入一个联系方式");
            return;
        }
        if(flag){
            data.qclxdh = newPhone['newTelAndPhone'];
        }else{
            mini.alert("联系电话或手机号有误，请重填");
            return;
        }
        var priNum = queryNameObj.getValue();
        var priNum1 = priNumObj.getValue();
        if(priNum1){
            priNum=priNum1;
        }
        if(!priNum){
            mini.alert("请填写迁移人员");
            return;
        }
        var nativeinproName = nativeinpro.getText();
        var nativeincityName = nativeincity.getText();
        var nativeincouName = nativeincou.getText();
        var nativeinvillName = nativeinvill.getText();
        data.nativeinproName = nativeinproName;
        data.nativeincityName = nativeincityName;
        data.nativeincouName = nativeincouName;
        data.nativeinvillName = nativeinvillName;
        data.priNum = priNum;
        var json = mini.encode(data);

        // 点击保存按钮 添加二次弹窗 确认是否发起迁移
        mini.confirm("确定要发起户籍迁出?","确定?",function(action){
            if (action == "ok"){
                $.ajax({
                    url: "/azbj/bjdxInfo/hjqr/addPrisonerMv/saveMvPrisoner",
                    type: "post",
                    data: {data: json},
                    success: function (success) {
                        if (success.code == 2){
                            mini.alert(success.data);
                        }else if (success.code == 1) {
                            mini.alert("保存成功","成功",function(){
                                window.CloseOwnerWindow('ok');
                            });
                        }else if (success.code == 5599) {
                            mini.alert(success.message);
                        }
                    }
                });
            }else {
                return;
            }
        })
    }

    function getQueryName(priNum){
        if(!priNum){
            priNum = queryNameObj.getValue();
        }
        if(!priNum){
            return;
        }
        $.ajax({
            url: "/azbj/bjdxInfo/qbrygl/query/getBaseInfoByPriNumMap?priNum="+priNum,
            type: "post",
            success: function (result) {
                if(result.data!=null){
                    var info = result.data;
                    var data={};
                    data.name=info.pname;
                    if(info.sex==0){
                        data.sex="未知的性别";
                    }else if(info.sex==1){
                        data.sex="男性";
                    }else if(info.sex==2){
                        data.sex="女性";
                    }else {
                        data.sex="未说明的性别";
                    }
                    data.idnum =info.idnum;
                    data.age = info.nl;
                    var hujidi = "";
                    if(info.nativeproName){
                        hujidi+=info.nativeproName;
                    }
                    if(info.nativecityName){
                        hujidi+=info.nativecityName;
                    }
                    if(info.nativecouName){
                        hujidi+=info.nativecouName;
                    }
                    if(info.nativevillName){
                        hujidi+=info.nativevillName;
                    }
                    if(info.nativenum){
                        hujidi+=info.nativenum;
                    }
                    data.hujidi = hujidi;
                    var juzhudi ="";
                    if(info.placeproName){
                        juzhudi+=info.placeproName;
                    }
                    if(info.placecityName){
                        juzhudi+=info.placecityName;
                    }
                    if(info.placecouName){
                        juzhudi+=info.placecouName;
                    }
                    if(info.placevillName){
                        juzhudi+=info.placevillName;
                    }
                    if(info.placenum){
                        juzhudi+=info.placenum;
                    }
                    data.juzhudi= juzhudi ;
                    data.priNumNew=info.priNum;
                    form2.setData(data);
                    queryNameObj.setText(info.pname);
                }
            }
        });
    }

    /**
     * 迁移地址
     * @param e
     */
    var urltemp = "/azbj/bjdxInfo/getDepart?codeType=2_1&codeId=-100";
    function onDeptChanged(e) {
        // nativeinpro nativeincity  nativeincou nativeinvill
        if("nativeinpro" == e){
            var value = nativeinpro.getValue();
            nativeinpro.setValue("");
            var url =  "/azbj/bjdxInfo/getDepart?codeType=2_1&codeId=-1";
            nativeinpro.setUrl(url);
            if(value!=''){
                nativeinpro.setValue(value);
            } else {
                nativeinpro.select(0);
            }
        }
        if("nativeincity" == e){
            var value = nativeincity.getValue();

            if(nativeinpro.getValue()==""){
                nativeincity.setUrl(urltemp);
                nativeincity.setValue("");
                nativeincou.setUrl(urltemp);
                nativeincou.setValue("");
                nativeinvill.setUrl(urltemp);
                nativeinvill.setValue("");
                return;
            }
            var codeId = nativeinpro.getValue();
            nativeincity.setValue("");
            var url = "/azbj/bjdxInfo/getDepart?codeType=2_1&codeId=" + codeId;
            nativeincity.setUrl(url);
            if(value!=''){
                nativeincity.setValue(value);
            } else {
                nativeincity.select(0);
            }
        }
        if("nativeincou" == e) {
            var value = nativeincou.getValue();

            if(nativeincity.getValue()==""){
                nativeincou.setUrl(urltemp);
                nativeincou.setValue("");
                nativeinvill.setUrl(urltemp);
                nativeinvill.setValue("");
                return;
            }
            var codeId = nativeincity.getValue();
            nativeincou.setValue("");
            var url = "/azbj/bjdxInfo/getDepart?codeType=2_1&codeId=" + codeId;
            nativeincou.setUrl(url);
            if(value!=''){
                nativeincou.setValue(value);
            } else {
                nativeincou.select(0);
            }
        }
        if("nativeinvill" == e){
            var value = nativeinvill.getValue();

            if(nativeincou.getValue()==""){
                nativeinvill.setUrl(urltemp);
                nativeinvill.setValue("");
                return;
            }
            var parent_code = nativeincou.getValue();
            nativeinvill.setValue("");
            var url = "/azbj/bjdxInfo/getQcStreet?parentCode=" + parent_code+"&priNum="+mini.get("priNumNew").getValue();
            nativeinvill.setUrl(url);
            if(value!=''){
                nativeinvill.setValue(value);
            } else {
                nativeinvill.select(0);
            }
        }
    }

    function onValueChanged(e) {
        if("nativeinpro" == e){
            nativeincity.setValue("");
            nativeincou.setValue("");
            nativeinvill.setValue("");
        }
        if("nativeincity" == e){
            nativeincou.setValue("");
            nativeinvill.setValue("");
        }
        if("nativeincou" == e) {
            nativeinvill.setValue("");
        }
    }

    function onFileUpload(e) {
        var idval = idObj.getValue();
        var prival = queryNameObj.getValue();
        var priNum1 = priNumObj.getValue();
        // alert(priNum1); 没有罪犯编号
        if(priNum1){
            prival=priNum1;
        }
        if(!prival){
            return;
        }
        // alert(prival); 有罪犯编号了
        var taskid = "13";
        var url = "/upload/user/uploadAppendixfile/view?1=1&id="+idval+"&priNum="+prival+"&taskId=" + taskid;
        commonEdit(url, null, null,600, 400, true,true,true,callback);
        // 回调函数
        function callback() {
            $.ajax({
                url: "/upload/downloadAppendixFile/getCountById?1=1&priNum="+ prival + "&taskId=13" + "&id="+ idval,
                type: "get",
                success: function (success) {
                    $("#msg1").text("上传成功" + success.data + "条!");
                }
            })
            grid.reload();
        }
    }

    function close(action){
        if(window.CloseOwnerWindow){
            window.CloseOwnerWindow(action);
        }else{
            window.close();
        }
    }

    // 获取迁移页面的id priNum等
    function GetData() {
        var idval = idObj.getValue();
        var prival = queryNameObj.getValue();
        var priNum1 = priNumObj.getValue();
        if(priNum1){
            prival=priNum1;
        }
        if(!prival){
            return;
        }
        var data = {priNum: prival, id: idval, taskId: '13'};
        return data;
    }
</script>
</body>
</html>